﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyVoteMVC.Data.Repositories;
using System.Data.Objects;
using System.Data;

namespace MyVoteMVC.Data
{
    /// <summary>
    /// 操作数据库工具=。=
    /// </summary>
    public interface IUnitOfWork:IDisposable
    {
        /// <summary>
        /// 是否存在事务
        /// </summary>
        bool IsInTransaction { get; }

        /// <summary>
        /// 开始事务
        /// </summary>
        void BeginTransaction();

        /// <summary>
        /// 开始事务
        /// </summary>
        /// <param name="isolationLevel">操作等级</param>
        void BeginTransaction(IsolationLevel isolationLevel);

        /// <summary>
        /// 提交事务
        /// </summary>
        void CommitTransaction();

        /// <summary>
        /// 回滚
        /// </summary>
        void Rollback();

        /// <summary>
        /// 提交数据库
        /// </summary>
        void Commit();

        /// <summary>
        /// 提交数据库
        /// </summary>
        /// <param name="saveOptions">保存选项</param>
        void Commit(SaveOptions saveOptions);

        /// <summary>
        /// 获取相关实体(TEntity)的知识库
        /// </summary>
        /// <typeparam name="TEntity">相关实体类型</typeparam>
        /// <returns>知识库</returns>
        IRepository<TEntity> GetRepository<TEntity>() where TEntity : class;

        /// <summary>
        /// 获取只用于后台管理的知识库
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <returns></returns>
        IAdminRepository<TEntity> GetAdminRepository<TEntity>() where TEntity : class;
    }
}
